home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / ingres04.lzh / source / monitor / branch.c next >
Encoding:
C/C++ Source or Header  |  1993-01-20  |  1.4 KB  |  93 lines

  1. # include    "monitor.h"
  2. # include    <ingres.h>
  3. # include    <aux.h>
  4. # include    <unistd.h>
  5.  
  6.  
  7. /*
  8. **  BRANCH
  9. **
  10. **    The "filename" following the \b op must match the "filename"
  11. **    which follows some \k command somewhere in this same file.
  12. **    The input pointer is placed at that point if possible.  If
  13. **    the label does not exist, an error is printed and the next
  14. **    character read is an EOF.
  15. **
  16. **    Trace Flags:
  17. **        33
  18. */
  19.  
  20. branch()
  21. {
  22.     register char    c;
  23.     register int    i;
  24.     extern char    getch();
  25.  
  26. #    ifdef xMTR2
  27.     if (tTf(33, -1))
  28.         printf(">>branch: ");
  29. #    endif
  30.  
  31.     /* see if conditional */
  32.     while ((c = getch()) > 0)
  33.         if (c != ' ' && c != '\t')
  34.             break;
  35.     if (c == '?')
  36.     {
  37.         /* got a conditional; evaluate it */
  38.         Oneline = TRUE;
  39.         macinit(getch, 0, 0);
  40.         i = expr();
  41.  
  42.         if (i <= 0)
  43.         {
  44.             /* no branch */
  45. #            ifdef xMTR2
  46.             if (tTf(33, 0))
  47.                 printf("no branch\n");
  48. #            endif
  49.             getfilenm();
  50.             return;
  51.         }
  52.     }
  53.     else
  54.     {
  55.         ungetc(c, Input);
  56.     }
  57.  
  58.     /* get the target label */
  59.     if (branchto(getfilenm()) == 0)
  60.         if (branchto(macro("{default}")) == 0)
  61.         {
  62.             GiveEof = TRUE;
  63.             printf("Cannot branch\n");
  64.         }
  65.     return;
  66. }
  67.  
  68.  
  69. branchto(label)
  70. char    *label;
  71. {
  72.     char        target[100];
  73.     register char    c;
  74.  
  75.     smove(label, target);
  76.     if (fseek(Input, 0L, SEEK_SET))
  77.     {
  78.         printf("Cannot branch on a terminal\n");
  79.         return (1);
  80.     }
  81.  
  82.     /* search for the label */
  83.     while ((c = getch()) > 0)
  84.     {
  85.         if (c != '\\')
  86.             continue;
  87.         if (getescape(0) != C_MARK)
  88.             continue;
  89.         if (sequal(getfilenm(), target))
  90.             return;
  91.     }
  92. }
  93.